//
//  EmojiKeyboardViewModel.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/5/4.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

class EmojiKeyboardViewModel: NSObject {
    //数据准备 表情数组
    //单例,随时可以拿到数组来使用
    static let shareEmojiViewModel:EmojiKeyboardViewModel = EmojiKeyboardViewModel()
    //保存表情bundle
    var emojiBundle:NSBundle = {
       
       let path = NSBundle.mainBundle().pathForResource("Emoticons.bundle", ofType: nil)
        return NSBundle(path: path!)!
    }()
    
    //保存所有表情的数组
    lazy var allEmojis:[[EmojiModel]] = {
        let defaultEmoji:[EmojiModel] = self.loadEmojiWithPath("default/info.plist")
        let enoji:[EmojiModel] = self.loadEmojiWithPath("emoji/info.plist")
        let lxh:[EmojiModel] = self.loadEmojiWithPath("lxh/info.plist")
        return [
            [EmojiModel](),
            defaultEmoji,
            enoji,
            lxh
        ]
    }()
    
//    根据路文件名获取表情数组的方法
    private func loadEmojiWithPath(filePath: String) -> [EmojiModel]{
//        搜索对应路径
        let path = emojiBundle.pathForResource(filePath, ofType: nil)
//        使用数接受对应plist文件
        let dicts = NSArray(contentsOfFile: path!)
//        字典转模型
        var tempArray = [EmojiModel]()
        
        for value in dicts! {
            let model = EmojiModel(dict: value as! [String : AnyObject])
            tempArray.append(model)
        }
        //        返回数组
        
        return tempArray
    }

}
